/*
 * junzhinuo all rights received.
 */
package com.junzhinuo.cqpzxx.adapter.email;

import java.util.Properties;
import javax.annotation.Resource;
import org.apache.commons.mail.DefaultAuthenticator;
import org.apache.commons.mail.Email;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.HtmlEmail;
import org.apache.commons.mail.SimpleEmail;
import org.springframework.stereotype.Repository;

/**
 *
 * @author Didy
 */
@Repository
public class EmailAdapter {

    @Resource
    Properties config;

    public void sendEmail(String subject, String msg, String to, String bcc) throws EmailException {

        Email email = new HtmlEmail();

        email.setHostName(config.getProperty("smtp.host"));
        email.setSmtpPort(Integer.valueOf(config.getProperty("smtp.port")));
        email.setAuthenticator(new DefaultAuthenticator(
                config.getProperty("smtp.user"),
                config.getProperty("smtp.pass")));
        email.setSSLOnConnect(true);
        email.setFrom(config.getProperty("smtp.from"));
        email.setSubject(subject);
        email.setMsg(msg);
        email.addTo(to);
        email.addBcc(bcc);
        email.addReplyTo(to);
        email.addReplyTo(bcc);
        email.setCharset("utf-8");
        email.send();

    }

}
